package cz.schovjan.proj.dao.impl;

import java.util.List;

import org.hibernate.Session;

import cz.schovjan.proj.dao.IAdminDao;
import cz.schovjan.proj.entity.UserEntity;
import cz.schovjan.proj.util.HibernateUtil;

/**
 * Implementace IAdminDao.
 * @author schovjan
 * 
 */
public class HibernateAdminDaoImpl implements IAdminDao {
	
	private static final String FIND_ALL = "select u from UserEntity as u where u.role = 2";

	
	@SuppressWarnings("unchecked")
	@Override
	public List<UserEntity> findAll() {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		
		List<UserEntity> result = session.createQuery(FIND_ALL).list();
		
		session.getTransaction().commit();
		session.close();

		return result;
	}

}
